function _editDetailsContent() {
    $("#headArea").empty();
    $("#content").empty();
    var text = $("#detail").val();
    if(text==""){
        Feng.error("请在下方文本区粘贴详情!");
    }

    parseAndShowXMLtoHtml(text, 'headArea', 'content', 'bottom_preview');
}
function deleteEvent(i) {
    $("#oldEvent"+i).remove();
}

function parseAndShowXMLtoHtml(text,topId,contentId,bottomId){
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(text,"text/xml");
    var adv = xmlDoc.getElementsByTagName('adv')[0];
    var title = adv.getAttribute('title');
    localStorage.setItem("title",title);
    for (var i = 0; i < adv.childElementCount; i++) {
        var node = adv.childNodes[i];
        if (node.nodeName == 'head') {
            if (node.childElementCount > 0) {
                var node = node.childNodes[0];
                if (node.nodeName == 'image') {

                    var fileId="";
                    var _url = node.getAttribute('src');
                    var fileUrl=_url.substring(26);

                    var ajax = new $ax(Feng.ctxPath + "/pfFile/getIdByUrl", function(data){
                        if(data.code == 100){
                            Feng.error(data.message);
                        }else{
                            fileId=data;
                        }

                    },function(data){
                        Feng.error("添加失败!" + data.responseJSON.message + "!");
                    });
                    ajax.set("fileUrl",fileUrl);
                    ajax.start();
                    $("#head option[value='2']").attr("selected","selected");
                    var picTemplate="<label class='col-sm-2 control-label'>图片id</label><div class='col-sm-10'><input type='title' class='form-control' id='HeadId'style='width: 70%;font-size: 25px;font-weight: bold;color: #101010;' value='"+fileId+"'></div>";
                    $("#"+topId).append(picTemplate);

                } else if (node.nodeName == 'video') {

                    var fileId="";
                    var _url = node.getAttribute('src');
                    var fileUrl=_url.substring(26);

                    var ajax = new $ax(Feng.ctxPath + "/pfFile/getIdByUrl", function(data){
                        if(data.code == 100){
                            Feng.error(data.message);
                        }else{
                            fileId=data;
                        }

                    },function(data){
                        Feng.error("失败!" + data.responseJSON.message + "!");
                    });
                    ajax.set("fileUrl",fileUrl);
                    ajax.start();
                    $("#head option[value='3']").attr("selected","selected");
                    var videoTemplate="<label class='col-sm-2 control-label'>视频id</label><div class='col-sm-10'><input type='video' class='form-control' id='HeadId'style='width: 70%;font-size: 25px;font-weight: bold;color: #101010;' value='"+fileId+"'></div>";
                    $("#"+topId).append(videoTemplate);


                }else if (node.nodeName == 'title') {
                    var content=node.textContent;
                    $("#"+topId).empty();
                    $("#head option[value='5']").attr("selected","selected");
                    var Template=" <div class=\"form-group\" style=\"margin-top: 10px\">" +
                        "        <label class=\"col-sm-2 control-label\">内容</label>" +
                        "        <div class=\"col-sm-10\">" +
                        "            <input class=\"form-control\" id=\"headTitle\"\n" +
                        "                   style=\"width: 70%;font-size: 25px;font-weight: bold;color: #101010;\" value="+content+" >" +
                        "        </div>" +
                        "    </div>";
                    $("#"+topId).append(Template);

                }
            }
        } else if (node.nodeName == 'title') {
            var content=node.textContent;
            var titleTemplate="<div class=\"form-group\" style=\"margin-top: 10px\" id=\"oldEvent"+i+"\">\n" +
                "        <label class=\"col-sm-2 control-label\">标题</label>\n" +
                "        <div class=\"col-sm-10\">\n" +
                "            <input type=\"title\" class=\"form-control\" id=\"text\"\n" +
                "                   style=\"width: 70%;font-size: 25px;font-weight: bold;color: #101010;\" value="+content+">\n" +
                "        </div>\n" +
                "<div style='margin-left: 16.5%;'><button type=\"button\"  style='margin-top: 3px;' class=\"btn btn-danger button-margin\"  onclick=\"deleteEvent("+i+")\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;取消\n" +
                "</button></div>"
                "    </div>";
            $("#"+contentId).append(titleTemplate);

        } else if (node.nodeName == 'text') {
            var content=node.textContent;
            var bodyTemplate="<div class=\"form-group\" style=\"margin-top: 10px\" id=\"oldEvent"+i+"\">\n" +
                "        <label class=\"col-sm-2 control-label\">正文</label>\n" +
                "        <div class=\"col-sm-10\">\n" +
                "            <textarea id=\"textArea\" style=\"width: 100%;height: 120px;font-size: 19px;color:#878787;\">"+content+"</textarea>" +
                "        </div>\n" +
                "<div style='margin-left: 16.5%'><button type=\"button\" class=\"btn btn-danger button-margin\"  onclick=\"deleteEvent("+i+")\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;取消\n" +
                "</button></div>"
                "    </div>";
            $("#"+contentId).append(bodyTemplate);
        } else if (node.nodeName == 'html') {
            var content=node.getAttribute('src');
            var htmlTemplate="<div class=\"form-group\" style=\"margin-top: 10px\" id=\"oldEvent"+i+"\">\n" +
                "        <label class=\"col-sm-2 control-label\">h5</label>\n" +
                "        <div class=\"col-sm-10\">\n" +
                "            <input type=\"html\" class=\"form-control\" id=\"text\"\n" +
                "                   style=\"width: 70%;color: #101010;\" value="+content+">\n" +
                "        </div>\n" +
                "<div style='margin-left: 16.5%;'><button type=\"button\"  style='margin-top: 3px;' class=\"btn btn-danger button-margin\"  onclick=\"deleteEvent("+i+")\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;取消\n" +
                "</button></div>"
            "    </div>";
            $("#"+contentId).append(htmlTemplate);

        }else if (node.nodeName == 'image') {
            var fileId="";
            var _url = node.getAttribute('src');
            var fileUrl=_url.substring(26);

            var ajax = new $ax(Feng.ctxPath + "/pfFile/getIdByUrl", function(data){
                if(data.code == 100){
                    Feng.error(data.message);
                }else{
                    fileId=data;
                }

            },function(data){
                Feng.error("失败!" + data.responseJSON.message + "!");
            });
            ajax.set("fileUrl",fileUrl);
            ajax.start();
            var picTemplate="<div class=\"form-group\" style=\"margin-top: 10px\" id=\"oldEvent"+i+"\">\n" +
                "        <label class=\"col-sm-2 control-label\">图片id</label>\n" +
                "        <div class=\"col-sm-10\">\n" +
                "            <input type=\"pic\" class=\"form-control\" id=\"\"\n" +
                "                   style=\"width: 70%;font-size: 25px;font-weight: bold;color: #101010;\"  value="+fileId+">\n" +
                "        </div>\n" +
                "<div style='margin-left: 16.5%;margin-top: 3px;'><button style='margin-top: 3px;' type=\"button\" class=\"btn btn-danger button-margin\"  onclick=\"deleteEvent("+i+")\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;取消\n" +
                "</button></div>"
                "    </div>";
            $("#"+contentId).append(picTemplate);

        }  else if (node.nodeName == 'video') {
            var fileId="";
            var _url = node.getAttribute('src');
            var thumb=node.getAttribute('thumb');
            var scTime=thumb.split(",")[1].substring(2)/1000;
            var fileUrl=_url.substring(26);
            var ajax = new $ax(Feng.ctxPath + "/pfFile/getIdByUrl", function(data){
                if(data.code == 100){
                    Feng.error(data.message);
                }else{
                    fileId=data;
                }

            },function(data){
                Feng.error("失败!" + data.responseJSON.message + "!");
            });
            ajax.set("fileUrl",fileUrl);
            ajax.start();
            var videoTemplate="<div class=\"form-group\" style=\"margin-top: 10px\" id=\"oldEvent"+i+"\">\n" +
                "        <label class=\"col-sm-2 control-label\">视频id</label>\n" +
                "        <div class=\"col-sm-10\">\n" +
                "            <input type=\"video\" class=\"form-control\" id=\"\"\n" +
                "                   style=\"width: 70%;font-size: 25px;font-weight: bold;color: #101010;\"  value="+fileId+">\n" +
                "<div>\n" +
                "                <label class=\"control-label\" style=\"margin-left: -11.5%;margin-top: 2%\">截帧秒</label>\n" +
                "                <input  type=\"scTime\" class=\"form-control\"\n" +
                "                       style=\"width: 20%;font-size: 25px;font-weight: bold;color: #101010;margin-top: -3.8%\" placeholder=\"\" value="+scTime+">\n" +
                "            </div>" +
                "        </div>\n" +
                "<div style='margin-left: 16.5%;margin-top: 3px;'><button style='margin-top: 3px;' type=\"button\" class=\"btn btn-danger button-margin\"  onclick=\"deleteEvent("+i+")\" id=\"\">\n" +
                "    <i class=\"fa fa-remove\"></i>&nbsp;取消\n" +
                "</button></div>"
            "    </div>";
            $("#"+contentId).append(videoTemplate);



            // var element = _createVideoElement(node);
            // _appendSceneMarginDivWithElement(contentId, element);
        }

























        function _createTitleElement(node) {
            var __sizeAttributes = node.getAttribute('font')
            var _sizeAttributes = [];
            if (__sizeAttributes != null) {
                _sizeAttributes = __sizeAttributes.split(',');
            }
            var _font = 25;
            if (_sizeAttributes.count > 0) {
                _font = _sizeAttributes[0]
            }
            var __styleAttributes = node.getAttribute('style');
            var _styleAttributes = [];
            if (__styleAttributes != null) {
                _styleAttributes = __sizeAttributes.split(',');
            }
            var _lineSpace = 9;
            if (_styleAttributes.count > 0) {
                _lineSpace = _styleAttributes[0];
            }
            var _paraSpace = 30;
            if (_styleAttributes.count > 1) {
                _paraSpace = _styleAttributes[1];
            }
            var _aligment = 'justify';
            if (_styleAttributes.count > 2) {
                if (_styleAttributes[2] == 'L') {
                    _aligment = 'left'
                } else if (_styleAttributes[2] == 'C') {
                    _aligment = 'center'
                } else if (_styleAttributes[2] == 'R') {
                    _aligment = 'right'
                }
            }
            var _color = node.getAttribute('color');
            if (_color == null) {
                _color = '#101010';
            }
            var style = '';
            style += 'font-size:' + _font + 'px;';
            style += 'color:' + _color + ';';
            style += 'line-height:' + (_font + _lineSpace) + 'px;';
            style += 'text-align:' + _aligment + ';';
            style += 'font-weight:bold;';

            var element = document.createElement("p");
            element.setAttribute('style', style);
            var text = document.createTextNode(node.textContent);
            element.appendChild(text);
            var scene = document.getElementById(contentId);
            scene.appendChild(element);
            return element;
        }
        function _createTextElement(node) {
            var __sizeAttributes = node.getAttribute('font')
            var _sizeAttributes = [];
            if (__sizeAttributes != null) {
                _sizeAttributes = __sizeAttributes.split(',');
            }
            var _font = 19;
            if (_sizeAttributes.count > 0) {
                _font = _sizeAttributes[0]
            }
            var _isBold = false;
            if (_sizeAttributes.count > 1) {
                if (_sizeAttributes[1] == 'B') {
                    _isBold = true;
                }
            }
            var __styleAttributes = node.getAttribute('style');
            var _styleAttributes = [];
            if (__styleAttributes != null) {
                _styleAttributes = __sizeAttributes.split(',');
            }
            var _lineSpace = 9;
            if (_styleAttributes.count > 0) {
                _lineSpace = _styleAttributes[0];
            }
            var _paraSpace = 30;
            if (_styleAttributes.count > 1) {
                _paraSpace = _styleAttributes[1];
            }
            var _aligment = 'justify';
            if (_styleAttributes.count > 2) {
                if (_styleAttributes[2] == 'L') {
                    _aligment = 'left'
                } else if (_styleAttributes[2] == 'C') {
                    _aligment = 'center'
                } else if (_styleAttributes[2] == 'R') {
                    _aligment = 'right'
                }
            }
            var _color = node.getAttribute('color');
            if (_color == null) {
                _color = '#878787';
            }
            var style = '';
            style += 'font-size:' + _font + 'px;';
            style += 'color:' + _color + ';';
            style += 'line-height:' + (_font + _lineSpace) + 'px;';
            if (_isBold) {
                style += 'font-weight:bold;';
            }
            style += 'text-align:' + _aligment;

            var element = document.createElement("p");
            element.setAttribute('style', style);
            var text = document.createTextNode(node.textContent);
            element.appendChild(text);
            var scene = document.getElementById(contentId);
            scene.appendChild(element);
            return element
        }
        function _createImageElement(node) {
            var _url = node.getAttribute('src');
            var element = document.createElement('img');
            element.setAttribute('src', _url);
            element.setAttribute('width', _width);
            element.setAttribute('height', _height);
            return element;
        }
        function _createVideoElement(node) {
            var _url = node.getAttribute('src');
            var __sizeAttributes = node.getAttribute('size');
            var _sizeAttributes = [];
            var _width = 300;
            var _height = 300 * 405 / 720;
            if (__sizeAttributes != null) {
                var arr = __sizeAttributes.split('x');
                if (arr.count > 1) {
                    var w = parseFloat(arr[0]);
                    var h = parseFloat(arr[1]);
                    if (w > 0 && h > 0) {
                        _height = _width * h / w;
                    }
                }
            }
            var _thumb = node.getAttribute('thumb');
            var element = document.createElement('video');
            element.setAttribute('src', _url);
            element.setAttribute('width', _width);
            // element.setAttribute('width', _width + 'vw');
            element.setAttribute('height', _height);
            element.setAttribute('controls', 'controls');
            element.setAttribute('poster', _thumb);
            element.setAttribute('style', 'background-color:black');
            element.setAttribute('preload', 'none');
            var text = document.createTextNode('浏览器不支持视频播放');
            element.appendChild(text);
            return element;
        }
        function _appendSceneMarginDivWithElement(scene, element) {
            var _width = 310;
            var _height = 310 * 405 / 720;
            var div = document.createElement('div');
            div.setAttribute('style', 'margin:30px 0px 30px 0px;width=310px;height=174.375px;');
            div.appendChild(element);
            var theScene = document.getElementById(scene);
            theScene.appendChild(div);
        }
    }
}